package com.jjkj.environmental.environmental.utils.pull

import com.jjkj.environmental.environmental.bean.response.SoapResponse
import com.jjkj.environmental.environmental.exception.PullConverterException
import okhttp3.ResponseBody
import retrofit2.Converter

@Suppress("UNCHECKED_CAST")
class PullResponseConverter<T> constructor(private val type: Class<T>) : Converter<ResponseBody, T> {
    override fun convert(value: ResponseBody): T {
        return when (type) {
            String::class.java -> value.string() as T
            SoapResponse::class.java -> PullConverter.convertResponse(value.string()) as T
            else -> throw PullConverterException("没有此类的方法")
        }
    }
}